package com.game.springbootstart.mapper;

import com.game.springbootstart.entity.Favorites;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.game.springbootstart.entity.Games;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 喜欢表 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2025-02-12
 */
@Mapper
public interface FavoritesMapper extends BaseMapper<Favorites> {

    @Insert("INSERT INTO favorites (user_id, game_id, created_at)\n" +
            "VALUES (#{userId},#{gameId},#{now});\n ")
    Boolean save(Long userId, Long gameId, LocalDateTime now);

    @Select("select * from games where id in (select game_id from favorites where user_id = #{userId})")
    List<Games> listBy(Long userId);

    @Delete("delete from favorites where user_id = #{userId} and game_id = #{gameId}")
    Boolean deleteBy(Long userId, Long gameId);

    @Select("select favorites.game_id from favorites where user_id = #{userId}")
    List<Long> selectFavorites(Long userId);
}
